package io.renren.modules.sys.service.impl;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.baomidou.mybatisplus.mapper.Wrapper;
import io.renren.common.annotation.DataFilter;
import io.renren.common.utils.Constant;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.SysDeptRegDao;
import io.renren.modules.sys.entity.SysDeptRegEntity;
import io.renren.modules.sys.service.SysDeptRegService;


@Service("sysDeptRegService")
public class SysDeptRegServiceImpl extends ServiceImpl<SysDeptRegDao, SysDeptRegEntity> implements SysDeptRegService {
    @Autowired
    private SysDeptRegServiceImpl sysDeptRegService;

    @Override
    @DataFilter(subDept = true, user = false)
    public PageUtils queryPage(Map<String, Object> params) {
        String parentId = (String) params.get("parentId");
        Page<SysDeptRegEntity> page = this.selectPage(
                new Query<SysDeptRegEntity>(params).getPage(),
                new EntityWrapper<SysDeptRegEntity>()//.where("parent_id={0}",parentId)
         .addFilterIfNeed(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
                        .eq("del_flag",0)
        );
        int countSysDept = 0 ;
        Wrapper<SysDeptRegEntity> wrapperSysDept = new EntityWrapper<>();
        countSysDept = sysDeptRegService.selectCount(wrapperSysDept
                .addFilterIfNeed(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
                .eq("del_flag",0));
        page.setTotal(countSysDept);
        return new PageUtils(page);
    }

}
